/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.umss.arqui10.modelo;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;


/** Registro
 *
 * @author rho1and0
 */
@Entity
class Registry implements Serializable {

    /**
     * Contiene datos preliminares del estado del Receptor de Servicios
     */
    @Column
    private String antecedent;

    /**
     * Contiene la descripcion tecnica del problema,
     * diagnostico y el trabajo realizado.
     **/
    @Column
    private String description;
    @Column
    private List<AccomplishedService> services;
    private List<Account> accounts; 

    private boolean open;

    public Registry(String antecendent) {
        this.antecedent = antecendent;
        this.description = "";
        this.services = new ArrayList<AccomplishedService>();
        this.open = true;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }


    /**
     * registramos al titular que se hara cargo de
     * pagar por los servicios registrados
     * @param holder
        return services;
     */

    void addServices(AccomplishedService service) {
        services.add(service);
    }
   
     /*
     * @param nameServ
     * @return
     */
    public Service getService(String nameServ) {
        Iterator<AccomplishedService> iterator = this.services.iterator();
        Service service = null;
        while (iterator.hasNext()) {
            AccomplishedService accService = iterator.next();
            if (accService.getName().equals(nameServ)) {
                service = accService;
            }
        }
        return service;
    }

    public String getAntecedent() {
        return antecedent;
    }

    public void deleteService(int i){
        services.remove(i);
    }

    public void setAntecedent(String antecedent) {
        this.antecedent = antecedent;
    }

    public BigDecimal getDebt(){
        BigDecimal ret=new BigDecimal(0);
        Iterator it = services.listIterator();
        while(it.hasNext()){
            ret.add( ((Service)it.next()).getCurrentPrice());
        }
        return ret;
    }

    public boolean isOpen() {
        return open;
    }

    public void setOpen(boolean open) {
        this.open = open;
    }

    void assignService(Service serv) {
        this.addServices(new AccomplishedService(serv));
    }
}
